package com.zjf.carpark.controller;


import com.zjf.carpark.entities.SysLog;
import com.zjf.carpark.service.impl.SysLogServiceImpl;
import com.zjf.carpark.utils.ResponseData;
import com.zjf.carpark.vo.SysLogPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.zjf.carpark.utils.CodeAndMessage.*;

/**
 * @description: 日志
 * @author: 张建飞
 * @createDate: 2019/12/23
 * @version: 1.0
 */
@CrossOrigin
@Controller
@RequestMapping("log")
public class LogController {

    @Autowired
    private SysLogServiceImpl sysLogService;

    ResponseData responseData;

    /**
     * 查看所有日志及模糊查询
     *
     * @param sysLogPageVo
     * @return
     */
    @RequestMapping("/showAll")
    @ResponseBody
    public ResponseData showAllLog(SysLogPageVO sysLogPageVo) {
        List<SysLog> logs = sysLogService.selectByMsg(sysLogPageVo);
        int totalCount = sysLogService.totalCount(sysLogPageVo);
        if (logs != null) {
            responseData = new ResponseData(CODE200, SUCCESS);
            responseData.putDataValue("logs", logs);
            responseData.putDataValue("totalCount", totalCount);
        } else {
            responseData = new ResponseData(CODE0, ERROR);
        }
        return responseData;
    }
}
